import sys
from PyQt6 import QtCore
from PyQt6.QtGui import *
from PyQt6.QtWidgets import *
from main_denglu import Ui_mainwindow
from write import enter
from PyQt6 import QtWidgets
import os


class Qmydenglu(QMainWindow):
    switch_login = QtCore.pyqtSignal()  # 跳转信号

    def __init__(self,parent=None):
        super().__init__(parent)
        self.win_login = Ui_mainwindow()
        self.write = enter()
        self.win_login.setupUi(self)
        self.setGeometry(700, 800, 700, 800)
        self.center()
        # self.setWindowFlag(QtCore.Qt.WindowType.FramelessWindowHint)
        # self.setAttribute(QtCore.Qt.WidgetAttribute.WA_TranslucentBackground)
        pix = QPixmap('菠萝屋ico.jpg')
        self.win_login.label_3.setPixmap(pix)
        self.win_login.pushu_denglu.clicked.connect(self.go_check)
        self.win_login.pushu_denglu.setShortcut('Return')

    def center(self):
        qr = self.frameGeometry()  # 得到一个指定主窗口几何形状的矩形
        cp = self.screen().availableGeometry().center()  # 计算出显示器的分辨率，通过分辨率得出中心点
        qr.moveCenter(cp)  # 设置为屏幕的中心，矩形大小不变
        self.move(qr.topLeft())

    def paintEvent(self, event):
        painter = QPainter(self)
        pixmap = QPixmap("登录界面背景.png")
        # 绘制窗口背景，平铺到整个窗口，随着窗口改变而改变
        painter.drawPixmap(self.rect(), pixmap)

    def go_check(self):
        psd = self.win_login.password.text()
        self.write.__init__()
        if self.write.mate(psd):
            self.switch_login.emit()

        else:
            QtWidgets.QMessageBox.critical(self, "wring", "密码错误")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon('菠萝屋.jpg'))
    myWidget = Qmydenglu()
    myWidget.show()
    sys.exit(app.exec())
